<!DOCTYPE html>
<html>
<head>
    <title>审核界面</title>
    {% include 'system/common/header.html' %}</head>
<link rel="stylesheet" href="{{ url_for('static', filename='system/admin/css/other/user.css') }}"/>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">申报类型</label>
                <div class="layui-input-inline">
                    <select name="type">
                        <option value="">请选择</option>
                        <option value="1">报废申请</option>
                        <option value="2">采购申请</option>
                    </select>
                </div>
                <label class="layui-form-label">申报时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="create_at" class="layui-input" id="time" placeholder="yyyy-MM-dd">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="audit-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="audit-table" lay-filter="audit-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="audit-bar">

{% if authorize("system:approve:tools_pass") %}
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="pass"><i
                class="layui-icon layui-icon-edit"> 通过</i>
        </button>
    {% endif %}
    {% if authorize("system:approve:tools_detail") %}
        <button class="pear-btn pear-btn-warming pear-btn-sm" lay-event="detail"><i
                class="layui-icon layui-icon-vercode"> 详情</i>
        </button>
    {% endif %}
    {% if authorize("system:approve:tools_reback") %}
        <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="reback"><i
                class="layui-icon layui-icon-delete"> 驳回</i>
        </button>
    {% endif %}
</script>


</script>

{% include 'system/common/footer.html' %}
<script>

    function render_status(d) {
        if (d.status === 0) {
            return '<span class="layui-badge layui-bg-gray">待审核</span>'
        } else if (d.status === 1) {
            return '<span class="layui-badge layui-bg-green">审核通过</span>'
        } else if (d.status === 2) {
            return '<span class="layui-badge layui-bg-red">审核不通过</span>'
        }
    }

    function render_type(d) {
        if (d.type === 1) {
            return '<li><span class="layui-badge-dot layui-bg-green"></span>报废申报</li>'
        } else if (d.type === 2) {
            return '<li><span class="layui-badge-dot layui-bg-cyan"></span>采购申报</li>'
        } else if (d.type === 3) {
            return '<li><span class="layui-badge-dot layui-bg-orange"></span>借阅申报</li>'
        }
    }


    layui.use(['table', 'form', 'jquery', 'popup', 'common'], function () {
        let table = layui.table
        let form = layui.form
        let $ = layui.jquery
        let popup = layui.popup
        var laydate = layui.laydate;

        let MODULE_PATH = '/system/approve/'

        let cols = [
            [
                {title: 'id', field: 'id', align: 'center'},
                {title: '申报发起人', field: 'requesterName', align: 'center'},
                {title: '申报人ID', field: 'requesterId', align: 'center'},
                {title: '申报类型', field: 'type', align: 'center', width: 100, templet: render_type},
                {title: '申报状态', field: 'status', align: 'center', templet: render_status},
                {title: '申报发起时间', field: 'create_at', align: 'center'},
                {title: '操作', toolbar: '#audit-bar', align: 'center', width: 240}
            ]
        ]

        laydate.render({
            elem: '#time',
            max: 0,
        });

        table.render({
            elem: '#audit-table',
            url: MODULE_PATH + '/pass/data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#audit-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        })

        table.on('tool(audit-table)', function (obj) {
            if (obj.event === 'reback') {
                window.reback(obj)
            } else if (obj.event === 'pass') {
                window.pass(obj)
            } else if (obj.event === 'detail') {
                window.detail(obj)
            }
        })

        table.on('toolbar(audit-table)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh()
            }
        })


        window.detail = function (obj) {
            layer.open({
                type: 2,
                title: '详情',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'pass/tools_detail/' + obj.data['id']
            });

        }

        window.pass = function (obj) {
            layer.prompt({title: '请填写意见', formType: 2}, function (value, index, elem) {
                let loading = layer.load()
                $.ajax({
                    url: MODULE_PATH + 'pass/tools_pass/' + obj.data['id'],
                    dataType: 'json',
                    type: 'put',
                    contentType:'application/json;charset=UTF-8',
                    data: JSON.stringify({value}),
                    success: function (result) {
                        layer.close(loading)
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                layer.closeAll(); // 关闭所有 layer 层
                                obj.del();
                                window.refresh()
                            })
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000})
                        }
                    }
                })
            })
        }

        window.reback = function (obj) {
            layer.confirm('确定要驳回吗？', {icon: 3, title: '提示'}, function (index) {

                layer.prompt({title: '请填写意见', formType: 2}, function (value, index, elem) {
                    let loading = layer.load()
                    $.ajax({
                        url: MODULE_PATH + 'pass/tools_reback/' + obj.data['id'],
                        dataType: 'json',
                        type: 'put',
                        contentType:'application/json;charset=UTF-8',
                        data: JSON.stringify({value}),
                        success: function (result) {
                            layer.close(loading)
                            if (result.success) {
                                layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                    layer.closeAll(); // 关闭所有 layer 层
                                    obj.del();
                                    window.refresh()
                                })
                            } else {
                                layer.msg(result.msg, {icon: 2, time: 1000})
                            }
                        }
                    })
                })
            })
        }

        // 简易搜索部分
        form.on('submit(audit-query)', function (data) {
            {#console.log(data.field)#}
            window.refresh(data.field)
            return false
        })

        window.refresh = function (param) {
            table.reload('audit-table', {where: param})
        }
    })
</script>
</html>